package com.jackrain.nea.fc.dl.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLPurAdjQtyToF4Mapper {

    @SelectProvider(type = ViewDLPurAdjQtySql.class, method = "findPurAdjQtyData")
    List<HashMap> selPurAdjQtyData(@Param("id") Object[] id);

    @SelectProvider(type = ViewDLPurAdjQtySql.class, method = "findPurAdjQtyItemData")
    List<HashMap> selPurAdjQtyItemData(@Param("id") Long id);

    class ViewDLPurAdjQtySql {

        public String findPurAdjQtyData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID,BILL_NO,CP_C_STORE_ID,CP_C_SUPPLIER_ID,ADJ_DATE,REMARK,CREATIONDATE," +
                            "OWNERENAME,MODIFIERNAME,MODIFIERENAME,MODIFIEDDATE");
                    FROM("DL_B_PUR_ADJ_QTY");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                    WHERE("ACCEPTE_STATUS=2");
                }
            }.toString();
        }

        public String findPurAdjQtyItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_PRO_ECODE,ADJ_BILL,SUP_PRICE,ADJ_MONEY,ORI_PRICE,CUR_PRICE,PRICE_LIST,REMARK,PRICE_MGT,AMT_MGT,PRICE_NON_TAX,AMT_NON_TAX");
                    FROM("DL_B_PUR_ADJ_QTY_ITEM");
                    WHERE("DL_B_PUR_ADJ_QTY_ID =" + id);
                }
            }.toString();
        }


    }


}
